/*************************************************************************
	> File Name: 003.判断数字在指定进制下是否为回文数.c
	> Author: Maureen 
	> Mail: Maureen@qq.com 
	> Created Time: 日  8/22 20:09:26 2021
 ************************************************************************/

#include <stdio.h>

int isPalindrome(int n, int base) {
    if (n < 0) return 0;

    int x = n, sum = 0;
    while (x) {
        sum = sum * base + x % base;
        x /= base;
    }
    return sum == n;
}

int main() {
    int n, base;
    scanf("%d%d", &n, &base);
    if (isPalindrome(n, base)) printf("Yes\n");
    else printf("No\n");
    return 0;
}
